package com.excel;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.lexer.Lexer;
import org.htmlparser.tags.TableTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import com.excel.read.Config;

import jxl.write.WriteException;

public class ResultSetTest {

	static String schemal = "MATICWEB";
	static List tableNames = null;

	public static void main(String args[]) {
		//Config.generateTable("d:\\");
		ResultSetTest db = new ResultSetTest();
		try {
			db.init();
		} catch (WriteException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

	}

	public void init() throws WriteException, IOException {
		String URL = "jdbc:oracle:thin:@192.168.100.201:1521:DEV";
		String user = "MATICWEB";
		String password = "MATICWEB";
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection con = DriverManager.getConnection(URL, user, password);			
			getTableMeta(con, "AD_MENU");		
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}




	public void getTableMeta(Connection connection, String table)
			throws WriteException, IOException, SQLException {

		Statement stmt = connection.createStatement();
		ResultSet rs = stmt
				.executeQuery("select  AD_MENU_ID, NAME, CREATED from "
						+ schemal + "." + table);
		String formatStr = "基本信息(ID:AD_MENU_ID,城市名:NAME);(创建时间:CREATED)";
		ExcelWriter excelWrite = new ResultSetExcelWriter("e:\\a.xls", rs,
				formatStr);
		// excelWrite.setSheetName("测试数据");
		// excelWrite.init();
		// excelWrite.writeExcel();

		rs = stmt.executeQuery("select AD_MENU_ID, NAME, CREATED from "
				+ schemal + "." + table);
		excelWrite = new ResultSetExcelWriter("e:\\b.xls", rs, formatStr);
		// excelWrite.setPosition(5, 12);
		excelWrite.setTableDisplayName("测试表格1");
		excelWrite.setSheetName("测试数据2");
		excelWrite.setMode(ExcelWriter.FILE_CREATE_OR_READ,
				ExcelWriter.SHEET_CREATE_OR_READ);
		excelWrite.init();
		excelWrite.writeExcel();

	}

	

	public static String getHTML() {
		return "<table id=\"table_d\"><tr>	<td>dasd</td><td>dsa</td></tr><tr>	<td>dasd</td><td>dsa</td></tr><tr>	<td>dasd</td><td>dsa</td></tr></table>";
	}

}
